/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.NVK;

import DAO.CTPNhapKhoDao;
import DAO.HoaDonDao;
import DAO.NhaCungCapDao;
import DAO.NhanVienDao;
import DAO.PNhapKhoDao;
import DAO.SanPhamDao;
import GUI.Var;
import POJO.CTPNhapKho;
import POJO.NhaCungCap;
import POJO.NhanVien;
import POJO.PNhapKho;
import POJO.SanPham;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Kim
 */
public class frXemPhieuNhapKho extends javax.swing.JInternalFrame {

	/**
	 * Creates new form frXemPhieuNhapKho
	 */
	private int TSD;// tong so dong trong bang hoa don
	private int THT; //trang hiện tại
	private int SD;// hien thi bao nhieu dong tron trang
	private DefaultTableModel model = null;
	private DefaultTableModel model2 = null;

	public frXemPhieuNhapKho() {
		initComponents();

		TSD = soDongDuLieu();
		THT = 0;
		SD = 30;

		load(SD, THT);
		if (model.getRowCount() > 0) {
			//tbHoaDonSelectedRow() =0;
			loadCT(0);
		}
		setTxt();
		lbNVDN.setText(Var.NV.getTenNV());

	}

	private void setTxt() {
		lbPhanTrang.setText(Integer.toString(THT + 1) + "/" + Integer.toString(TSD / SD + 1));
	}

	private int soDongDuLieu() {
		int tmp = 0;
		PNhapKhoDao dao = new PNhapKhoDao();
		try {
			tmp = dao.laySoDong();
		} catch (Exception e) {
		}
		return tmp;
	}

	public void DefaultFrom() {
		model = new DefaultTableModel();
		model2 = new DefaultTableModel();
		// tao cac cot
		this.model.addColumn("Mã sản phẩm");
		this.model.addColumn("Ngày");
		this.model.addColumn("XX");
		this.model.addColumn("YY");

		this.model2.addColumn("STT");
		this.model2.addColumn("Số PN");
		this.model2.addColumn("Tên nhà CC");



	}

	public void load(int soDong, int trangSo) {
		ArrayList<PNhapKho> dsPNhapKho = null;

		try {
			dsPNhapKho = PNhapKhoDao.layDanhSachByNhanVienPhanTrang(Var.NV.getMaNV(), soDong, trangSo);

		} catch (Exception e) {
		}

		NhaCungCapDao dao = new NhaCungCapDao();
		DefaultFrom();
		int stt = 1;
		for (PNhapKho pnk : dsPNhapKho) {
			int mancc = pnk.getMaNCC();
			NhaCungCap ncc = dao.layByMa(mancc);
			Object[] items = new Object[]{
				pnk.getSoPNK(),
				pnk.getNgayNhap(),
				pnk.getMaNCC(),
				pnk.getMaNVPhuTrach()};
			Object[] items2 = new Object[]{stt,
				pnk.getSoPNK(),
				ncc.getTenNCC()
			};
			model.addRow(items);
			model2.addRow(items2);
			stt++;

		}
		jtDanhSachPhieuNhap.setModel(model2);

		int[] va = {20, 20, 60};
		int[] pt = new int[3];
		for (int l = 0; l < 3; l++) {
			pt[l] = jtDanhSachPhieuNhap.getWidth() * va[l] / 100;
			jtDanhSachPhieuNhap.getColumnModel().getColumn(l).setPreferredWidth(pt[l]);

		}
	}

	/**
	 * This method is called from within the constructor to initialize the
	 * form. WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
       // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
       private void initComponents() {

              jPanel1 = new javax.swing.JPanel();
              jLabel1 = new javax.swing.JLabel();
              jPanel3 = new javax.swing.JPanel();
              jPanel4 = new javax.swing.JPanel();
              jScrollPane2 = new javax.swing.JScrollPane();
              jtDanhSachPhieuNhap = new javax.swing.JTable();
              jPanel11 = new javax.swing.JPanel();
              jButton9 = new javax.swing.JButton();
              jButton10 = new javax.swing.JButton();
              jButton11 = new javax.swing.JButton();
              jButton12 = new javax.swing.JButton();
              lbPhanTrang = new javax.swing.JLabel();
              jLabel7 = new javax.swing.JLabel();
              lbNVDN = new javax.swing.JLabel();
              jPanel6 = new javax.swing.JPanel();
              jPanel8 = new javax.swing.JPanel();
              jLabel2 = new javax.swing.JLabel();
              jtfSoPNK = new javax.swing.JTextField();
              jLabel3 = new javax.swing.JLabel();
              jtfNgayNhap = new javax.swing.JTextField();
              jLabel4 = new javax.swing.JLabel();
              jtfNhaCungCap = new javax.swing.JTextField();
              jLabel6 = new javax.swing.JLabel();
              jtfTriGia = new javax.swing.JTextField();
              jLabel12 = new javax.swing.JLabel();
              jPanel7 = new javax.swing.JPanel();
              jScrollPane1 = new javax.swing.JScrollPane();
              jtCTPhieuNhapKho = new javax.swing.JTable();
              jPanel5 = new javax.swing.JPanel();
              jbtnHienThi = new javax.swing.JButton();

              setClosable(true);
              setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
              setIconifiable(true);
              setMaximizable(true);
              setResizable(true);

              jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
              jLabel1.setText("XEM PHIẾU NHẬP KHO ");

              javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
              jPanel1.setLayout(jPanel1Layout);
              jPanel1Layout.setHorizontalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel1)
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              jPanel1Layout.setVerticalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(0, 0, Short.MAX_VALUE))
              );

              jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.LINE_AXIS));

              jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh sách phiếu nhập"));
              jPanel4.setToolTipText("");

              jtDanhSachPhieuNhap.setModel(new javax.swing.table.DefaultTableModel(
                     new Object [][] {

                     },
                     new String [] {
                            "STT", "Số phiếu nhập", "Nhà cung cấp"
                     }
              ));
              jtDanhSachPhieuNhap.addMouseListener(new java.awt.event.MouseAdapter() {
                     public void mouseClicked(java.awt.event.MouseEvent evt) {
                            jtDanhSachPhieuNhapMouseClicked(evt);
                     }
              });
              jScrollPane2.setViewportView(jtDanhSachPhieuNhap);

              jButton9.setText("|<");
              jButton9.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton9ActionPerformed(evt);
                     }
              });

              jButton10.setText("<");
              jButton10.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton10ActionPerformed(evt);
                     }
              });

              jButton11.setText(">|");
              jButton11.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton11ActionPerformed(evt);
                     }
              });

              jButton12.setText(">");
              jButton12.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton12ActionPerformed(evt);
                     }
              });

              lbPhanTrang.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              lbPhanTrang.setText("0");

              javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
              jPanel11.setLayout(jPanel11Layout);
              jPanel11Layout.setHorizontalGroup(
                     jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel11Layout.createSequentialGroup()
                            .addContainerGap(30, Short.MAX_VALUE)
                            .addComponent(jButton9)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton10)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lbPhanTrang)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton12)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton11)
                            .addContainerGap(31, Short.MAX_VALUE))
              );
              jPanel11Layout.setVerticalGroup(
                     jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel11Layout.createSequentialGroup()
                            .addGap(0, 0, Short.MAX_VALUE)
                            .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jButton9)
                                   .addComponent(jButton10)
                                   .addComponent(jButton11)
                                   .addComponent(jButton12)
                                   .addComponent(lbPhanTrang)))
              );

              jLabel7.setText("Người lập:");

              lbNVDN.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              lbNVDN.setText("[Nhân viên đăng nhập]");

              javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
              jPanel4.setLayout(jPanel4Layout);
              jPanel4Layout.setHorizontalGroup(
                     jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                     .addComponent(jPanel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                     .addGroup(jPanel4Layout.createSequentialGroup()
                            .addGap(27, 27, 27)
                            .addComponent(jLabel7)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lbNVDN)
                            .addContainerGap())
              );
              jPanel4Layout.setVerticalGroup(
                     jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(lbNVDN)
                                   .addComponent(jLabel7))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
              );

              jPanel3.add(jPanel4);

              jPanel6.setLayout(new java.awt.BorderLayout());

              jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin phiếu nhập kho"));

              jLabel2.setText("Số phiếu nhập:");

              jtfSoPNK.setEditable(false);

              jLabel3.setText("Ngày nhập:");

              jtfNgayNhap.setEditable(false);

              jLabel4.setText("Nhà cung cấp:");

              jtfNhaCungCap.setEditable(false);

              jLabel6.setText("Trị giá phiếu nhập:");

              jtfTriGia.setEditable(false);

              jLabel12.setText("VNĐ");

              javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
              jPanel8.setLayout(jPanel8Layout);
              jPanel8Layout.setHorizontalGroup(
                     jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel8Layout.createSequentialGroup()
                            .addGap(60, 60, 60)
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addGroup(jPanel8Layout.createSequentialGroup()
                                          .addGap(18, 18, 18)
                                          .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                 .addComponent(jtfNgayNhap, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                                                 .addComponent(jtfSoPNK)))
                                   .addGroup(jPanel8Layout.createSequentialGroup()
                                          .addGap(18, 18, 18)
                                          .addComponent(jtfTriGia))
                                   .addGroup(jPanel8Layout.createSequentialGroup()
                                          .addGap(18, 18, 18)
                                          .addComponent(jtfNhaCungCap)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel12)
                            .addContainerGap())
              );
              jPanel8Layout.setVerticalGroup(
                     jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel8Layout.createSequentialGroup()
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jLabel2)
                                   .addComponent(jtfSoPNK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jLabel3)
                                   .addComponent(jtfNgayNhap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jLabel4)
                                   .addComponent(jtfNhaCungCap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jLabel6)
                                   .addComponent(jtfTriGia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel12))
                            .addGap(0, 0, Short.MAX_VALUE))
              );

              jPanel6.add(jPanel8, java.awt.BorderLayout.PAGE_START);

              jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Chi tiết phiếu nhập kho"));

              jtCTPhieuNhapKho.setModel(new javax.swing.table.DefaultTableModel(
                     new Object [][] {

                     },
                     new String [] {
                            "STT", "Mã SP", "Tên sản phẩm", "Số lượng ", "Giá nhập"
                     }
              ));
              jScrollPane1.setViewportView(jtCTPhieuNhapKho);

              javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
              jPanel7.setLayout(jPanel7Layout);
              jPanel7Layout.setHorizontalGroup(
                     jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 369, Short.MAX_VALUE)
              );
              jPanel7Layout.setVerticalGroup(
                     jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)
              );

              jPanel6.add(jPanel7, java.awt.BorderLayout.CENTER);

              jPanel3.add(jPanel6);

              jbtnHienThi.setText("Hiển thị");
              jbtnHienThi.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtnHienThiActionPerformed(evt);
                     }
              });

              javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
              jPanel5.setLayout(jPanel5Layout);
              jPanel5Layout.setHorizontalGroup(
                     jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel5Layout.createSequentialGroup()
                            .addGap(294, 294, 294)
                            .addComponent(jbtnHienThi)
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              jPanel5Layout.setVerticalGroup(
                     jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                            .addGap(0, 0, Short.MAX_VALUE)
                            .addComponent(jbtnHienThi))
              );

              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 654, Short.MAX_VALUE)
                                   .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGap(0, 0, 0))
              );
              layout.setVerticalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
              );

              pack();
       }// </editor-fold>//GEN-END:initComponents

    private void jbtnHienThiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnHienThiActionPerformed
	    // TODO add your handling code here:
	    load(SD, 0);
    }//GEN-LAST:event_jbtnHienThiActionPerformed

    private void jtDanhSachPhieuNhapMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtDanhSachPhieuNhapMouseClicked
	    // TODO add your handling code here:
	    int dong = this.jtDanhSachPhieuNhap.getSelectedRow();
	    loadCT(dong);
    }//GEN-LAST:event_jtDanhSachPhieuNhapMouseClicked

       private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
		// TODO add your handling code here:
		// ve dau tien
		THT = 0;
		load(SD, THT);
		if (model.getRowCount() > 0) {
			//tbHoaDonSelectedRow() =0;
			loadCT(0);
		}
		setTxt();

       }//GEN-LAST:event_jButton9ActionPerformed

       private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
		// TODO add your handling code here:
		//ve trang truoc
		if (THT != 0) {
			THT -= 1;
			load(SD, THT);
			if (model.getRowCount() > 0) {
				//tbHoaDonSelectedRow() =0;
				loadCT(0);
			}
		}
		setTxt();

       }//GEN-LAST:event_jButton10ActionPerformed

       private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
		// TODO add your handling code here:
		// ve cuoi

		THT = TSD / SD;
		load(SD, THT);
		if (model.getRowCount() > 0) {
			//tbHoaDonSelectedRow() =0;
			loadCT(0);
		}
		setTxt();

       }//GEN-LAST:event_jButton11ActionPerformed

       private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
		// TODO add your handling code here:
		if (THT < TSD / SD) {
			THT += 1;
			load(SD, THT);
			if (model.getRowCount() > 0) {
				//tbHoaDonSelectedRow() =0;
				loadCT(0);
			}
		}
		setTxt();

       }//GEN-LAST:event_jButton12ActionPerformed

	public void loadCT(int dong) {
		// load tren text
		int soPNK = (Integer) model.getValueAt(dong, 0);
		Date NgayNhap = (Date) model.getValueAt(dong, 1);
		int maNCC = (Integer) model.getValueAt(dong, 2);
		//	int maNVPhuTrach = (Integer) model.getValueAt(dong, 3);
		NhaCungCapDao ncc = new NhaCungCapDao();
		NhaCungCap dsncc = ncc.layByMa(maNCC);
		//NhanVienDao nv = new NhanVienDao();
		//	NhanVien dsnv = nv.layByMa(maNVPhuTrach);

		jtfSoPNK.setText(String.valueOf(soPNK));
		jtfNgayNhap.setText(Var.hienThiNgayVN(NgayNhap));
		jtfNhaCungCap.setText(dsncc.getTenNCC());
		//	jtfNhanVienPhuTrach.setText(dsnv.getTenNV());

		// load luoi chi tiet 

		SanPhamDao dao = new SanPhamDao();
		SanPham sp = new SanPham();
		ArrayList<CTPNhapKho> dsCTPNhapKho = CTPNhapKhoDao.layDanhSachBySoPNK(soPNK);
		String[] columns = new String[]{"STT", "Mã SP", "Tên sản phẩm", "Số lượng", "Giá nhập"};
		DefaultTableModel model = new DefaultTableModel(null, columns);
		int t = 1;
		double gia = 0;
		for (CTPNhapKho ctpnk : dsCTPNhapKho) {
			sp = dao.layDanhSachByMaSP(ctpnk.getMaSP());
			Object[] items = new Object[]{t,
				ctpnk.getMaSP(),
				sp.getTenSP(),
				ctpnk.getSoLuong(),
				ctpnk.getGiaNhap()
			};
			t++;
			model.addRow(items);
			gia += Double.valueOf(ctpnk.getGiaNhap());
		}
		jtfTriGia.setText(Double.toString(gia));
		jtCTPhieuNhapKho.setModel(model);
		int[] va = {10, 10, 30, 25, 25};
		int[] pt = new int[5];
		for (int l = 0; l < 5; l++) {
			pt[l] = jtCTPhieuNhapKho.getWidth() * va[l] / 100;
			jtCTPhieuNhapKho.getColumnModel().getColumn(l).setPreferredWidth(pt[l]);

		}
	}

	
       // Variables declaration - do not modify//GEN-BEGIN:variables
       private javax.swing.JButton jButton10;
       private javax.swing.JButton jButton11;
       private javax.swing.JButton jButton12;
       private javax.swing.JButton jButton9;
       private javax.swing.JLabel jLabel1;
       private javax.swing.JLabel jLabel12;
       private javax.swing.JLabel jLabel2;
       private javax.swing.JLabel jLabel3;
       private javax.swing.JLabel jLabel4;
       private javax.swing.JLabel jLabel6;
       private javax.swing.JLabel jLabel7;
       private javax.swing.JPanel jPanel1;
       private javax.swing.JPanel jPanel11;
       private javax.swing.JPanel jPanel3;
       private javax.swing.JPanel jPanel4;
       private javax.swing.JPanel jPanel5;
       private javax.swing.JPanel jPanel6;
       private javax.swing.JPanel jPanel7;
       private javax.swing.JPanel jPanel8;
       private javax.swing.JScrollPane jScrollPane1;
       private javax.swing.JScrollPane jScrollPane2;
       private javax.swing.JButton jbtnHienThi;
       private javax.swing.JTable jtCTPhieuNhapKho;
       private javax.swing.JTable jtDanhSachPhieuNhap;
       private javax.swing.JTextField jtfNgayNhap;
       private javax.swing.JTextField jtfNhaCungCap;
       private javax.swing.JTextField jtfSoPNK;
       private javax.swing.JTextField jtfTriGia;
       private javax.swing.JLabel lbNVDN;
       private javax.swing.JLabel lbPhanTrang;
       // End of variables declaration//GEN-END:variables
}
